package com.juzipi.demo.config;



import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;

/**
 * 暂时不用
 */

//@Configuration
public class InterceptorConfig implements WebMvcConfigurer {


    @Autowired
    private TokenInterceptor tokenInterceptor;


    //构造方法
//    public InterceptorConfig(TokenInterceptor tokenInterceptor){
//        this.tokenInterceptor = tokenInterceptor;
//    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        ArrayList<String> excludePath = new ArrayList<>();
        excludePath.add("/user_register");//注册
        excludePath.add("/login");//登录
        excludePath.add("/logout");//退出
        excludePath.add("/static/**");//静态资源
        excludePath.add("/swagger-ui/index.html/**");//静态资源
        excludePath.add("/assets/**");//静态资源

        registry.addInterceptor(tokenInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(excludePath);
        WebMvcConfigurer.super.addInterceptors(registry);


    }


    /**
     * 跨域吧
     * @param registry
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOriginPatterns("*")
                .allowCredentials(true)
                .allowedMethods("GET","POST","DELETE","PUT","PATCH","OPTIONS","HEAD")
                .maxAge(3600 * 24);
    }
}
